<?php

class CategoryController extends BaseController
{
	
	public function getIndex()
	{
		$categories = Category::all()->toArray();
		$_link = array("_rel" => "self", "self" => array("href" => ""));
		
		for($i = 0; $i < count($categories); $i++)
		{
			$_link['_rel'] = "self";
			$_link['self']['href'] = "http://integrated:85/product/category/" .$categories[$i]['id'];
			 
			$categories[$i]['_links'] = $_link;
		}
		
		return Response::json($categories);
	}
	
	public function getFind($id)
	{
		$category = Category::find($id);
		$_link = array("_rel" => "self", "self" => array("href" => ""));
		
		$_link['_rel'] = "self";
		$_link['self']['href'] = "http://integrated:85/product/category/" .$category['id'];
			 
		$category['_links'] = $_link;
		
		if(empty($category))
		{
			return "False";
		}
		
		return Response::json($category);
	}
}
